package l.l.w.CodingInterviews;

/**
 * Created by llw on 2018/4/19/0019.
 */
public class 素数 {
    public static void main(String[] args) {
        int k = 10;
        int kthSushu = new 素数().getKthSushu(k);
        System.out.println(kthSushu);
    }
    public int getKthSushu(int k){
        if(k == 1) return 2;
        int j = 1;
        for(int i = 3;;++i){
            if((i >> 2) == 0)continue;
            if(isSushu(i)){
                j++;
                if(j == k){
                    return i;
                }
            }
        }
    }

    private boolean isSushu(int i) {
        int sqrt = (int) Math.sqrt(i);
        for(int j = 3; j <= sqrt; ++j){
            if(i % j == 0)return false;
        }
        return true;
    }
}
